﻿using System;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Zvezda.FSO2.DB;

namespace FSO
{
    public partial class UserControlSearchMaterial : UserControl, InterfaceSearchControl
    {
        private bool _openOnDblClick;

        

        public UserControlSearchMaterial()
        {
            InitializeComponent();
            radGridViewList.MultiSelect = true;
        }

        #region Interface

        public bool OpenOnDoubleClick
        {
            get
            {
                return _openOnDblClick;
            }
            set
            {
                _openOnDblClick = value;
            }
        }

        public bool EnableFiltering
        {
            get
            {
                return radGridViewList.EnableFiltering;
            }
            set
            {
                radGridViewList.EnableFiltering = value;
            }
        }

        public DataRow SelectedRow
        {
            get
            {
                DataRow dr;
                if (radGridViewList.SelectedRows.Count > 0)
                {
                    dr = (((DataRowView)(radGridViewList.SelectedRows.First()).DataBoundItem)).Row;
                }
                else
                {
                    dr = null;
                }
                return dr;
            }
        }

        public DataSet OwnerDataSet
        {
            get { return dataSetFSO1; }
            set { dataSetFSO1 = (DataSetFSO)value; }
        }

        public GridViewSelectedRowsCollection SelectedRows
        {
            get { return radGridViewList.SelectedRows; }
        }

        public void RefreshList()
        {
            nsI_MATERIALTableAdapter1.Fill(dataSetFSO1.NSI_MATERIAL);
        }

        #endregion

        private void UserControlSearchMaterial_Load(object sender, EventArgs e)
        {
            nsI_MATERIALTableAdapter1.Fill(dataSetFSO1.NSI_MATERIAL);

            this.InitializeGridView();
        }

        private void InitializeGridView()
        {
            GridViewTextBoxColumn colName = new GridViewTextBoxColumn("NAME", dataSetFSO1.NSI_MATERIAL.NAMEColumn.ColumnName);
            colName.HeaderText = "Наименование";

            radGridViewList.MasterTemplate.Columns.Clear();
            radGridViewList.MasterTemplate.Columns.Add(colName);

            radGridViewList.DataSource = dataSetFSO1.NSI_MATERIAL;
        }
    }
}
